$(function () {
    //加载数据
    userStudyRecord(1);
    initLayerDate("#beginTime",true);
    initLayerDate("#endTime",true);
    $('body').on('click','#btnSelcet',function(){
        userStudyRecord(1);
    }).on("click",'.openReport',function(){
        var id = $(this).data("id");
        if(id=="0"){
            Zepto.toast("你还没有做过该章节得随堂练习");
            return;
        }
        var byCourseId = $(this).data("bycourse");
        var courseId = $(this).data("course");
        var catalogId = $(this).data("catalog");
        var scorePercent = $(this).data("percen");
        var pass = $(this).data("pass");

        window.location.href ="/web/uc/course/play/record/userPracticeRecord?examRecordId="+id+"&courseId="+courseId+"&catalogId="+catalogId+"&scorePercent="+scorePercent+"&pass="+pass+"&byCourseId=" +byCourseId
    }).on('click','.learn',function(){
        var byCourseId = $(this).data("bycourse");
        var courseId = $(this).data("course");
        var catalogId = $(this).data("catalog");
        var url ="/web/uc/play/toPlayCourse?type=LOBBY&courseId="+byCourseId+"&catalogId="+catalogId;
        if(courseId!=byCourseId){
            url+="&packageId="+courseId;
        }
        window.location.href=baseloaction +url;
    });

    function initLayerDate(selector, time) {
        var format = time ?  'YYYY-MM-DD hh:mm:ss' : 'YYYY-MM-DD';
        if ($(selector).length > 0) {
            laydate({
                elem: selector,
                format: format,
                istime: time
            });
        }
    }
    /**
     * 加载课程学习记录
     * @param pageNo 页码
     */
    function userStudyRecord(pageNo) {

        var _params = $('#search-form').serializeJSON();
        _params = JSON.stringify(_params);
        getPageAjaxData({
            url: baseloaction + '/web/uc/course/play/record/ajaxUserStudyRecord',
            contextId: 'user-study-record-list-box',
            pageNo: pageNo,
            params: _params,
            pageCall: userStudyRecord,
            callback: function (pageNo) {
                $('[data-toggle=tooltip]').tooltip();
                lazyCourseImage();
                lazyStudentImage();
            }
        });
    }
});